<?php
require_once('../../../../conf/config.php.inc');
require_once(SYBMAS_LIB_PATH.'/liblogin.php.inc');
require_once(SYBMAS_LAYOUT_PATH.'/layout.php.inc');
require_once(SYBMAS_LIB_PATH.'/libsybmas.php.inc');
require_once(SYBMAS_LAYOUT_PATH.'/menu.php.inc');
require_once('../../lib/libtablas.php.inc');
include_once('otorgarRevocar.php.inc');
verificar_inicio_sesion();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css"
	href="<?php echo LAYOUT_URI?>/sybmasstyle.css">
<script src="<?php echo LAYOUT_URI?>/jquery-1.2.1.min.js"
	type="text/javascript"></script>
<script src="<?php echo LAYOUT_URI?>/menu-collapsed.js"
	type="text/javascript"></script>
<link rel="stylesheet" type="text/css"
	href="<?php echo LAYOUT_URI?>/style.css" >
<link rel="stylesheet" type="text/css"
	href="<?php echo JAVASCRIPT_URI?>/tabs/tabs.css">
<script src="<?php echo JAVASCRIPT_URI?>/tabs/tabs.js"
	type="text/javascript"></script>
<script type="text/javascript" src="<?php echo JAVASCRIPT_URI?>/commons.js"></script>
<script type="text/javascript" src="otorgarRevocar.js"></script>

<title>.:: Sybmas - Otorgar/Revocar privilegios sobre tabla</title>
<!--[if lt IE 8]>
   <style type="text/css">
   li a {display:inline-block;}
   li a {display:block;}
   </style>
   <![endif]-->
</head>
<body>
<script src="<?php echo JAVASCRIPT_URI?>/tooltip/wz_tooltip.js"
	type="text/javascript"></script>
<div id="dialog">
<div class="title">Privilegios sobre objetos</div>

<form action="otorgarRevocar2.php" method="post" 
	target="otorgarRevocar_dialog" onsubmit="return verificarFormulario()"> 

<?php 
$dbname=false;
foreach($_POST as $key => $value){
	$$key=$value;
	echo "<input type='hidden' name='$key' value='$value'>\n";
}
?>
<?php
$cambio_bd_exitoso=true;
$sybuser_connection=start_default_sybuser_connection();
$sybmas_connection=start_sybmas_connection();
if($dbname){
	$cambio_bd_exitoso=sybase_select_db($dbname,$sybuser_connection);
}

if($cambio_bd_exitoso){
	$query="SELECT name FROM ";
	//sybase_set_message_handler("void_msg_handler",$sybuser_connection);
if(empty($userHasGrantOption)){
	$permitionList=array('SELECT', 'INSERT', 'DELETE', 'UPDATE', 'REFERENCES');
}else{
	$permitionList=explode(',',$userHasGrantOption);
	echo "<script type=\"text/javascript\">setPrivilegesList('$userHasGrantOption')</script>";
	$userHasGrantOption=true;
}

$list_users=getUsers($dbname);
?>
	<h2>Otorgar/Revocar privilegios en tabla: <?php echo $tablename?></h2>
	<table border="1" width="100%" cellpadding="2">
		<tr>
			<th>Privilegios</th>	
			<th></th>	
			<th>P. Otorgados</th>
		</tr>
		<tr>
			<td rowspan="2" width="30%">
				<select name="allPrivilegesList[]" id="allPrivilegesList" multiple="multiple" size="12" style="width: 100%">
					<?php foreach ($permitionList as $permition){?>
					<option value="<?php echo $permition?>"><?php echo $permition?></option>
					<?php }?>
				</select>
			</td>	
			<td rowspan="2" width="8%" align="center">
				<input type="button" value="&gt;&gt;" id="btnAddPrivilege";
					onclick="swapListElements(document.getElementById('allPrivilegesList'),document.getElementById('grantedPrivileges'))" ><br >
				<input type="button" value="&lt;&lt;" id="btnRemovePrivilege";
					onclick="swapListElementsWithGrantOption(document.getElementById('grantedPrivileges'),document.getElementById('allPrivilegesList'))" >				
			</td>	
			<td rowspan="2" width="30%">
				<select id="grantedPrivileges" name="privileges[]" multiple="multiple" size="12"  style="width: 100%">
				</select>				
			</td>
			<td colspan="2">
				<input type="radio" id="grantToUser" name="grantToOpt" checked="checked" value="grantToUser" onclick="getUserAndGroups('<?php echo $dbname?>','U')">Usuario
				<input type="radio" id="grantToGroup" name="grantToOpt" value="grantToGroup" onclick="getUserAndGroups('<?php echo $dbname?>','G')">Grupo
				<br>				
				<select size="9" id="grantTo" name="grantTo" style="width: 100%" 
					onchange="getPrivilegesForUser('<?php echo $dbname?>','<?php echo $tableowner?>','<?php echo $tablename?>',this.options[this.selectedIndex].value)">
					<?php echo $list_users;?>
				</select> 
			</td>
		</tr>
		<tr>
			<td>
				<input type="checkbox" id="allPrivileges" name="allPrivileges" onclick="setAllPrivileges()">ALL
			</td>	
			<td>
				<input type="checkbox" id="withGrantOption" name="withGrantOption" >GRANT OPT.
			</td>	
		</tr>
	</table>			
<?php 			
}//if($cambio_bd_exitoso)
//Cerrando conexiones a la base de datos
//sybase_close($sybuser_connection);
?>
<hr>
<input type="submit" value="Continuar">
<input type="button" value="Cancelar" onclick="window.close();">
</form>
</div>
</body>
</html>